﻿using Microsoft.Practices.Unity;
using TickSharp.Core.Interfaces;

namespace TickSharp.DependencyResolution
{
    public class DependencyResolver : IDependencyResolver
    {
        private readonly IUnityContainer _unityContainer;

        public DependencyResolver()
            : this(new UnityContainer())
        {
        }

        private DependencyResolver(IUnityContainer unityContainer)
        {
            _unityContainer = unityContainer;
        }

        public void Register<TBase, TImpl>() where TImpl : TBase
        {
            _unityContainer.RegisterType<TBase, TImpl>();
        }

        public void RegisterInstance<TImpl>(TImpl instance)
        {
            _unityContainer.RegisterInstance(instance);
        }

        public TBase Resolve<TBase>()
        {
            return _unityContainer.Resolve<TBase>();
        }
    }
}